<?php
/**
 * 用户成为商家
 *
 * @copyright  Copyright (c) 2015-2025 NcPHP Inc. (http://www.ncphp.com)
 * @license    http://www.ncphp.com
 * @link       http://www.ncphp.com
 * @author	   NcPHP Team
 * @since      File available since Release v1.1
 */
defined('InNcPHP') or exit('Access Invalid!');

class member_merchantModel extends Model{

    public $state = array('0'=>'审核中','1'=>'审核通过','2'=>'审核失败');
    public $bank_state = array('10'=>'正在审核','20'=>'审核通过','30'=>'审核被拒');
	public function __construct(){
		parent::__construct('member_merchant');
	}

    /**
     * 获取一条记录的详细信息
     * @param array $condition
     * @param string $field
     * @return mixed
     */
	public function getMerchantInfo($condition = array(), $field = '*')
    {
        return $this->field($field)->where($condition)->find();
    }

    /**
     * 插入一条记录
     * @param array $params
     * @return mixed
     */
    public function addMerchant($params)
    {
        return $this->insert($params);
    }

    /**
     * 更新记录
     * @param array $condition
     * @param array $params
     * @return mixed
     */
    public function updateMerchant($condition, $params)
    {
        return $this->where($condition)->update($params);
    }


    /**
     * 获取记录数组
     * @param array $condition
     * @param string $field
     * @param string $order
     * @return mixed
     */
    public function getMerchantList($condition = array(), $field = '*', $order = 'merchant_id'){
	    return $this->field($field)->where($condition)->order($order)->select();
    }

    /**
     * 分页获取列表
     * @param array $condition
     * @param string $field
     * @param int $page
     * @param string $order
     * @return mixed
     */
    public function getMerchantListPage($condition = array(), $field = '*', $page = 0, $order = 'mc_apply_time desc'){
        return $this->field($field)->where($condition)->page($page)->order($order)->select();
    }

    /**
     * 获取所有商家分类的城市ID（去重复）
     */
    public function getMerchantCityId()
    {
        $city_list =  $this->where(array('is_disable'=>0,'mc_status'=>1))->field('city_id')->group('city_id')->select();
        return $city_list;
    }

    /**
     * 获取所有商家分类的地区ID（去重复）
     */
    public function getMerchantAreaId()
    {
        $city_list =  $this->where(array('is_disable'=>0,'mc_status'=>1))->field('area_id')->group('area_id')->select();
        return $city_list;
    }
    /**
     * 增加商家的金额记录
     */
    public function addMerchantMoney($merchant_id,$type,$money)
    {
        return $this->where(array('merchant_id'=>$merchant_id))->setInc($type,$money);
    }

    /**
     * 减少商家的金额
     */
    public function reduceMerchantMoney($merchant_id,$type,$money)
    {
        return $this->where(array('merchant_id'=>$merchant_id))->setDec($type,$money);
    }



    /**
     * 取得数量
     * @param array $condition
     */
    public function getMerchantCount($condition) {
        return $this->where($condition)->count();
    }





}
?>